package com.gxuwz.weather.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DBHelper extends SQLiteOpenHelper {

    private static final String DATABASE_NAME = "weather.db";

    private static final int DATABASE_VERSION = 3; // 更新版本号

    public DBHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // 创建 area 表
        String CREATE_AREA_TABLE = "CREATE TABLE area (" +
                "areaId TEXT PRIMARY KEY, " +
                "areaCn TEXT, " +
                "cityEn TEXT, " +
                "cityCn TEXT, " +
                "provEn TEXT, " +
                "areaEn TEXT, " +
                "provCn TEXT, " +
                "areaCode TEXT)";
        db.execSQL(CREATE_AREA_TABLE);
        Log.d("DBHelper", "Table 'area' created successfully");

        // 创建 myarea 表
        String CREATE_MYAREA_TABLE = "CREATE TABLE myarea (" +
                "id INTEGER PRIMARY KEY AUTOINCREMENT, " +
                "areaId TEXT, " +
                "areaCn TEXT, " +
                "cityEn TEXT, " +
                "cityCn TEXT, " +
                "provEn TEXT, " +
                "areaEn TEXT, " +
                "provCn TEXT, " +
                "areaCode TEXT)";
        db.execSQL(CREATE_MYAREA_TABLE);
        Log.d("DBHelper", "Table 'myarea' created successfully");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // 重新创建表
        onCreate(db);
    }
}
